package org.laizili.solution.leetcode;

/**
 * <a href="https://leetcode.cn/problems/valid-boomerang/">1037. 有效的回旋镖</a>
 * <p>
 * tags: 数学题; 二维平面三点共线
 * TODO: 叉乘; 点乘; 斜率;
 */
public class Problem1037 {
    private static class Solution {
        public boolean isBoomerang(int[][] points) {
            double slope1 = 0;
            boolean infinite1 = false;
            int dx1 = points[1][0] - points[0][0];
            int dy1 = points[1][1] - points[0][1];
            if (dx1 == 0 && dy1 == 0) {
                return false;
            } else if (dx1 == 0) {
                infinite1 = true;
            } else {
                slope1 = dy1 / ((double) (dx1));
            }
            double slope2 = 0;
            boolean infinite2 = false;
            int dx2 = points[2][0] - points[1][0];
            int dy2 = points[2][1] - points[1][1];
            if (dx2 == 0 && dy2 == 0) {
                return false;
            } else if (dx2 == 0) {
                infinite2 = true;
            } else {
                slope2 = dy2 / ((double) dx2);
            }
            if (infinite1 && infinite2) {
                return false;
            } else return infinite1 || infinite2 || slope1 != slope2;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution().isBoomerang(new int[][]{{1, 1}, {2, 2}, {3, 3}}));
    }
}
